/**
 * 
 */
package com.wolfpire.info.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.info.model.CommunicateCooperation;
import com.wolfpire.info.service.CommunicateCooperationService;
import com.wolfpire.system.common.AuthorityUtils;
import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.system.common.springmvc.PrincipalArgument;
import com.wolfpire.system.model.Authority;
import com.wolfpire.system.model.User;

/**
 * 闽台与国际交流合作情况控制器
 * @author lihd
 *
 */

@Controller
@RequestMapping("/communicateCooperation")
public class CommunicateCooperationController {
	
	@Resource private CommunicateCooperationService communicateCooperationService;
	
	@RequestMapping("/list")
	public ModelAndView list(@PrincipalArgument User user, @RequestParam Long menuId) {
		List<Authority> operAuthorities = AuthorityUtils.getAperAuthorities(user, menuId);
		return new ModelAndView("info/communicateCooperation/communicateCooperation_list", "operAuthorities", operAuthorities);
	}
	
	@ResponseBody
	@RequestMapping("/queryList")
	public EasyuiPagination<CommunicateCooperation> queryList(EasyuiPage<CommunicateCooperation>page, CommunicateCooperation filterCommunicateCooperation) {
		Page<CommunicateCooperation> communicateCooperations = this.communicateCooperationService.setPageDataList(page, filterCommunicateCooperation);
		return new EasyuiPagination<CommunicateCooperation>(communicateCooperations);
	}
	
	@ResponseBody
	@RequestMapping("/queryCCsList")
	public EasyuiPagination<Map<String, Object>> queryCCsList(EasyuiPage<Map<String, Object>>page, CommunicateCooperation filterCommunicateCooperation) {
		Page<Map<String, Object>> communicateCooperations = this.communicateCooperationService.setCCsPageDataList(page, filterCommunicateCooperation);
		return new EasyuiPagination<Map<String, Object>>(communicateCooperations);
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpSession session, CommunicateCooperation communicateCooperation) {
		ModelAndView mv = new ModelAndView("info/communicateCooperation/communicateCooperation_add");
		mv.getModelMap().addAttribute(communicateCooperation);
		return mv;
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public Result save(@PrincipalArgument User user, CommunicateCooperation communicateCooperation) {
		try {
			communicateCooperation.setCreateUserId(user.getId());
			communicateCooperation.setCreateUserName(user.getNickName());
			this.communicateCooperationService.saveOrUpdate(communicateCooperation);
			return new Result(true, "保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "保存失败");
		}
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(Long id) {
		ModelAndView mv = new ModelAndView("info/communicateCooperation/communicateCooperation_add");
		if (null != id) {
			CommunicateCooperation communicateCooperation = this.communicateCooperationService.getFullCommunicateCooperation(id);
			mv.addObject(communicateCooperation);
		}
		return mv;
	}
	
	@RequestMapping("/detail")
	public ModelAndView detail(@RequestParam(value = "id", required = true) Long id) {
		ModelAndView mv = new ModelAndView("info/communicateCooperation/communicateCooperation_detail");
		try {
			if (null != id) {
				CommunicateCooperation communicateCooperation = this.communicateCooperationService.getFullCommunicateCooperation(id);
				mv.addObject(communicateCooperation);
			}
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			return new ModelAndView("/proms/common/error");
		}
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public Result delete(@RequestParam(value="id") Long id) {
		try {
			this.communicateCooperationService.del(id);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}

}
